package com.burst.reptile.modular.zp.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.burst.reptile.modular.zp.entity.ZpReport;
import com.burst.reptile.modular.zp.form.ReportForm;
import com.burst.reptile.modular.zp.mapper.ZpReportMapper;
import com.burst.reptile.modular.zp.service.IZpReportService;

import cn.hutool.core.util.StrUtil;

/**
 * <p>
 * 举报信息 服务实现类
 * </p>
 *
 * @author wujin
 * @since 2020-06-29
 */
@Service
public class ZpReportServiceImpl extends ServiceImpl<ZpReportMapper, ZpReport> implements IZpReportService {

	@Override
	public int report(ReportForm reportForm) {
		Long articleId = reportForm.getArticleId();
		String reportContent = reportForm.getReportContent();
		String desc = reportForm.getDesc();
		ZpReport report = new ZpReport();
		report.setArticleId(articleId);
		StringBuilder buff = new StringBuilder();
		if(StrUtil.isNotEmpty(reportContent)) {
			buff.append(reportContent);
		}
		if(StrUtil.isNotEmpty(desc)) {
			buff.append(desc);
			buff.append(";");
		}
		report.setReportContent(buff.toString());
		return this.baseMapper.insert(report);
	}

	@Override
	public Page<ZpReport> pageList(Page<ZpReport> page, ZpReport report) {
		QueryWrapper<ZpReport> queryWrapper = new QueryWrapper<>();
		queryWrapper.orderByDesc("create_time");
		return this.page(page, queryWrapper);
	}

}
